# -*- encoding=utf8 -*-
__author__ = "yangxianming"

from airtest.core.api import *
# ST.PROJECT_ROOT = "E:\AirtestWorkSpace\fuyuanwaiUItest"
# using(r"E:\AirtestWorkSpace\fuyuanwaiUItest\common.air")
# from common import *

auto_setup(__file__)
# auto_setup(__file__, logdir=True, devices=["Android://127.0.0.1:5037/11748585?cap_method=javacap&ori_method=adbori",])

#拿到设备编号
import sys
args = sys.argv
devicePid = args[4].split("/")[3]
print("--------" + devicePid)
rootArr = args[2].split("\\")
scriptRoot = ""
for i in range(len(rootArr) - 1):
    scriptRoot = scriptRoot + rootArr[i] + "\\"
print("--------" + scriptRoot)

#对更目录下设变编号文件做注册登记操作 1代表在使用  0代表停止使用
with open(scriptRoot + devicePid, 'w') as f:
    f.write('1')
using(scriptRoot + "common.air")

from common import *
stop_app("com.alibaba.android.rimet")
start_app("com.alibaba.android.rimet")

try:
    sleep(1.0)
    openKoufu()
    sleep(1.0)
    openScene("shoujichongzhi")
    
    #点击按键不要让浮动助手挡住了数字键盘
    touch(Template(r"tpl1680058655393.png", record_pos=(-0.336, 0.502), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058664818.png", record_pos=(0.331, 0.503), resolution=(1080, 2244)))
    touch(Template(r"tpl1680512563639.png", record_pos=(-0.001, 0.502), resolution=(1080, 1920)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    touch(Template(r"tpl1680058681000.png", record_pos=(0.331, 0.656), resolution=(1080, 2244)))
    sleep(1.0)
    touch(Template(r"tpl1680058725816.png", record_pos=(-0.305, -0.165), resolution=(1080, 2244)))
    sleep(1.0)
    #划上去
    swipe((550, 1300), (550, 800))
    sleep(1.0)
    #点去充值
    touch(Template(r"tpl1680058928108.png", record_pos=(0.005, 0.585), resolution=(1080, 2244)))
    sleep(2.0)
    #点确认
    touch(Template(r"tpl1684482422280.png", record_pos=(0.219, 0.163), resolution=(1080, 1920)))
    sleep(1.0)
    
    
    #验证弹框
    assert_exists(Template(r"tpl1684482447983.png", record_pos=(-0.28, 0.677), resolution=(1080, 1920)), "弹出我们的收银台就对了")

except Exception as e:
    print(e)
finally:
    sleep(1.0)
    stop_app("com.alibaba.android.rimet")
    #完成测试等级设备为0以便被其他脚本使用
    with open(scriptRoot + devicePid, 'w') as f:
        f.write('0')
